package com.kongj18.mrio.dao;

import com.kongj18.mrio.domain.ResultExport;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ResultExportMapper {
    @Select("select * from result_export where province_export = #{provinceName} and item_name = #{itemName}")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "province_export", property = "provinceExport"),
            @Result(column = "province_import", property = "provinceImport"),
            @Result(column = "value", property = "value"),
            @Result(column = "item_name", property = "itemName")
    })
    List<ResultExport> findByProvinceExportAndItem(@Param("provinceName") String provinceName, @Param("itemName") String itemName);

    @Select(
            "<script>" +
                    "select * from result_export where item_name = #{itemName} and " +
                    "province_export in " +
                    "<foreach item='item' index='index' collection='provinces' open='(' separator=',' close=')'>" +
                        "#{item} " +
                    "</foreach>" +
            "</script>"
    )
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "province_export", property = "provinceExport"),
            @Result(column = "province_import", property = "provinceImport"),
            @Result(column = "value", property = "value"),
            @Result(column = "item_name", property = "itemName")
    })
    List<ResultExport> findByProvinceExportListAndItem(@Param("provinces") List<String> provinces, @Param("itemName") String itemName);

    @Select("select * from result_export")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "province_export", property = "provinceExport"),
            @Result(column = "province_import", property = "provinceImport"),
            @Result(column = "value", property = "value"),
            @Result(column = "item_name", property = "itemName")
    })
    List<ResultExport> getAll();

    @Select(
            "<script>" +
                    "select * from result_export where item_name = #{itemName} and " +
                    "province_import in " +
                    "<foreach item='item' index='index' collection='provinces' open='(' separator=',' close=')'>" +
                    "#{item} " +
                    "</foreach>" +
                    "</script>"
    )
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "province_export", property = "provinceExport"),
            @Result(column = "province_import", property = "provinceImport"),
            @Result(column = "value", property = "value"),
            @Result(column = "item_name", property = "itemName")
    })
    List<ResultExport> findByProvinceImportListAndItem(List<String> provinces, String itemName);
}
